from aip import AipNlp
from config import Config


def baidu_sim(text1, text2):
    """
    百度词语相似度
    :param text1: 词语1
    :param text2: 词语2
    :return: 相似度
    """
    APP_ID = Config.APP_ID
    API_KEY = Config.API_KEY
    SECRET_KEY = Config.SECRET_KEY
    # options = {}
    # options["model"] = "CNN"
    client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
    result = client.simnet(text1, text2)
    if "score" in result:
        return {"score": result['score']}
    else:
        return {"error": "error"}
